<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="库存查询" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<script src="/js/QueryList.js"></script>
<script language="javascript">
	function doSearch(){
		var stoId=document.getElementById("sto_id").value;
		var proTypeId=document.getElementById("pro_type_id").value;
		var proCode=encodeURIComponent(document.getElementById("pro_code").value.trim());
		var proName=encodeURIComponent(document.getElementById("pro_name").value.trim());
		var stoAmount=document.getElementById("sto_amount").value;
		var costType="";
		<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1}">
			costType=document.getElementById("cost_type").value;
		</c:if>
		window.location="/storehouse/StockSearch.ihtm?flag=1&sto_id="+stoId+"&pro_type_id="+proTypeId+"&pro_code="+proCode+"&pro_name="+proName+"&sto_amount="+stoAmount+"&cost_type="+costType;
	}
	
	function getSearchCondition(){
		var proCode=encodeURIComponent("<c:out value="${proCode}" />");
		var proName=encodeURIComponent("<c:out value="${proName}" />");
		var str="flag=1&sto_id=${stoId}&pro_type_id=${proTypeId}&pro_code="+proCode+"&pro_name="+proName+"&sto_amount=${stoAmount}&cost_type=${costType}";
		return str;
	}
	
	function doCancel(){
		window.close();
	}
	function doInit(){
		Window_Onload();
		if(window.screen.availWidth>900){
			var w=window.screen.availWidth*0.98;
			window.resizeTo(w,600);
			document.getElementById("mainDiv").style.width=(w-60)+"px";
			//居中
			var resizeWinTop=(window.screen.availHeight-600)/2;
			var resizeWinLeft=(window.screen.availWidth-w)/2;
			window.moveTo(resizeWinLeft,resizeWinTop);
		}
		document.getElementById("pro_name").focus();
	}
	function checkKey(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function doPrint(){
		var str=getSearchCondition();
		showWin(900,600,"/storehouse/StockSearch.ihtm?content_type=PRINT&"+str);
	}
	function doDownload(){
		var str=getSearchCondition();
		window.location="/storehouse/StockSearch.ihtm?content_type=EXCEL&"+str;
	}
</script>
</head>
<body oncontextmenu="return false" onLoad="doInit();" class="sheet">
<div class="sheet-main" style="width:860px" id="mainDiv">
  <div class="sheet-top">
    <div class="content">
      <h2>库存查询</h2>
      <p>查询当前库存量、低于安全库存的材料、超过最高库存的材料，支持以材料名称、材料名称拼音字头进行模糊查询</p>
    </div>
  </div>
  <div class="sheet-list">
    <div class="search-business">
      <div class="content">
        <table width="100%" id="searchTbl">
          <tbody>
            <tr>
              <td align="right">
				<select name='sto_id' id='sto_id' style="width:120px">
					<option value="">==请选择仓库==</option>
					<c:forEach var="item" items="${storehouseList}"><option value="${item.id}" <c:if test="${item.id==stoId}">selected</c:if>>${item.stoName}</option></c:forEach>
				</select>						
				<select name='pro_type_id' id='pro_type_id' style="width:180px">
					<option value="">==请选择材料类别==</option>
	  				<commonTag:createSelectTree list="${productTypeList}" emptyOption="0" defaultValue="${proTypeId}" />
	  			</select>
				<select name='sto_amount' id='sto_amount'>
					<option value="">==全部库存==</option>
					<option value="LOWER_MIN" <c:if test="${stoAmount=='LOWER_MIN'}">selected</c:if>>低于安全库存</option>
					<option value="UPPER_MAX" <c:if test="${stoAmount=='UPPER_MAX'}">selected</c:if>>高于最高库存</option>
					<option value="UPPER_ZERO" <c:if test="${stoAmount=='UPPER_ZERO'}">selected</c:if>>库存大于0</option>
				</select>
				<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1}">
				<select name='cost_type' id='cost_type'>
					<option value="NO_COST" <c:if test="${costType=='NO_COST'}">selected</c:if>>不显示单价</option>
					<option value="SHOW_COST" <c:if test="${costType=='SHOW_COST'}">selected</c:if>>显示单价</option>
				</select>
				</c:if>
	  			材料编号：<input type="text" class="TextBox"  id="pro_code" name="pro_code" onKeyUp="checkKey();" style="width:68px" value="<c:out value="${proCode}" />">
				品名规格：<input type="text" class="TextBox"  id="pro_name" name="pro_name" onKeyUp="checkKey();" style="width:68px" value="<c:out value="${proName}" />">
				<input type="button"  value=" 查 询" onClick="doSearch();"  class="buttom search-but">
				<c:if test="${list!=null}">
					<input type="button"  value=" 导 出" onClick="doDownload();" class="buttom  search-out" <c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';NO_EXPO;')!=-1}">disabled="true"</c:if>>
					<input type="button"  value=" 打 印" onClick="doPrint();" class="buttom search-print">
				</c:if>   
				</td>
            </tr>    
            </tbody>      
        </table>      	 
      </div>
	  <c:if test="${list!=null}">
	  <c:if test="${costType=='SHOW_COST' && (currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_TOTA;')==-1 && fn:indexOf(currentUser.privs,';STOR_COST;')!=-1)}">
      <div class="cue-info">
		<span>金额合计：${cost}元</span>
      </div>	
      </c:if>		
     <div class="table-list">
        <table width="100%">
          <tr>			
				<th  width="10%">材料类别</th>
				<th  width="10%">材料编号</th>
				<th  width="24%">品名规格</th>
				<c:if test="${costType=='SHOW_COST' && (currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1)}">
					<th  width="6%">单位</th>
					<th  width="8%">数量</th>
					<th  width="8%">单价</th>
					<th  width="10%">金额</th>
					<th  width="8%">安全库存</th>
					<th  width="8%">最高库存</th>
					<th  width="8%">所在仓库</th>
				</c:if>
				<c:if test="${costType!='SHOW_COST' || (currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';STOR_COST;')==-1)}">
					<th  width="10%">单位</th>
					<th  width="10%">数量</th>
					<th  width="10%">安全库存</th>
					<th  width="10%">最高库存</th>
					<th  width="16%">所在仓库</th>
				</c:if>
			</tr>
			<c:if test="${fn:length(list)==0}">
			<tr>
				<td colspan="10">没有库存数据</td>
			</tr>
			</c:if>
			<c:forEach var="item" items="${list}" varStatus="i">
			    <c:set var="defaultFontColor" value="#000000" />
			    <c:if test="${item.product.minLimit!=0 && item.stock.amount<item.product.minLimit }"><c:set var="defaultFontColor" value="#ff0000" /></c:if>
			    <c:if test="${item.product.maxLimit!=0 && item.stock.amount>item.product.maxLimit }"><c:set var="defaultFontColor" value="#ff0000" /></c:if>
				<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
				<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
				<tr class="${trClass}" index="${i.index+1}" defaultFontColor="${defaultFontColor}" style='cursor:pointer;color:${defaultFontColor};' ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
					<td>
						<input type="radio" name='query_checkbox' value="${i.index+1}" style="display:none">
						${item.productTypeName}
					</td>
					<td>${item.product.productCode}</td>
					<td>${item.product.productName} ${item.product.specification} ${item.product.marque}</td>
					<td>${item.product.unit}</td>
					<td><commonTag:parseBigDecimal source="${item.stock.amount}" /></td>
					<c:if test="${costType=='SHOW_COST' && (currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1)}">
						<td><commonTag:parseBigDecimal source="${item.unitPrice}" /></td>
						<td><commonTag:parseBigDecimal source="${item.stock.cost}" /></td>
					</c:if>
					<td>${item.product.minLimit}</td>
					<td>${item.product.maxLimit}</td>
					<td>${item.stoName}</td>
				</tr>
			</c:forEach>
		</table>
     </div>
	 </c:if>
 </div>
</div>
</div>
</body>
</html>